﻿using System.Collections.Generic;
using NsbExtensions.Endpoint.Management;
using NsbExtensions.Utilities;
using ObjectBuilder;

namespace NsbExtensions
{
    public abstract class ManagedEndpoint : MessagingEndpoint
    {
        public IEndpointManagementClientService EndpointManager { get; set; }

        /// <summary>
        /// Override this method to add some custom background service or services to the endpoint.
        /// This method registers the EndpointManager, so make sure you call base.RegisterLocalBackgroundServices(...)
        /// if you override this method.
        /// </summary>
        /// <param name="localServiceRegistry"></param>
        /// <param name="builder"></param>
        protected override void RegisterLocalBackgroundServices(List<IBackgroundService> localServiceRegistry,
                                                                IBuilder builder)
        {
            base.RegisterLocalBackgroundServices(localServiceRegistry, builder);
            if (EndpointManager != null)
                localServiceRegistry.Add(EndpointManager);
        }
    }
}